package com.jta.dao.impl;

import java.io.Serializable;
import java.util.List;


import com.jta.dao.intf.IBaseDao;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;


@Repository("tmsDao")
public class TmsBaseDaoImpl extends HibernateDaoSupport implements IBaseDao {

    protected HibernateTemplate tmsHibernateTemplate;


    @Autowired
    public void setTmsHibernateTemplate(HibernateTemplate tmsHibernateTemplate) {
        this.tmsHibernateTemplate = tmsHibernateTemplate;
        super.setHibernateTemplate(tmsHibernateTemplate);
    }


    @SuppressWarnings("rawtypes")
    @Override
    public List findAll(String hql) throws Exception {
        return tmsHibernateTemplate.find(hql);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public List query(String hql,Object value) throws Exception {
        return tmsHibernateTemplate.find(hql, value);
    }

    @Override
    public <T> Serializable save(T entity) throws Exception {
        Serializable s = tmsHibernateTemplate.save(entity);
        return s;
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T> List find(DetachedCriteria detachedCriteria) throws Exception {
        return tmsHibernateTemplate.findByCriteria(detachedCriteria);
    }
}